package com.saifan.wyy_ov.ui.communitylife;

import android.Manifest;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.saifan.wyy_ov.R;
import com.saifan.wyy_ov.config.Api;
import com.saifan.wyy_ov.data.bean.PopBean;
import com.saifan.wyy_ov.data.bean.RentalRequestBean;
import com.saifan.wyy_ov.data.bean.RoomInfoBean;
import com.saifan.wyy_ov.model.impl.GetData;
import com.saifan.wyy_ov.model.interfaces.IListViewOnClick;
import com.saifan.wyy_ov.ui.album.ui.PhotoAlbumActivity;
import com.saifan.wyy_ov.ui.home.MainActivity;

import com.saifan.wyy_ov.ui.property.CommentsPicAdapter;
import com.saifan.wyy_ov.ui.property.ComplaintandadviceActivity;
import com.saifan.wyy_ov.ui.property.DecorationApplyActivity;
import com.saifan.wyy_ov.ui.property.FeeQueryActivity;
import com.saifan.wyy_ov.ui.property.PhotographActivity;
import com.saifan.wyy_ov.ui.property.ProgressQueryActivity;
import com.saifan.wyy_ov.ui.property.QuestionnaireInfoActivity;
import com.saifan.wyy_ov.ui.property.RepairActivity;
import com.saifan.wyy_ov.ui.property.VisitorManageActivity;
import com.saifan.wyy_ov.ui.view.BaseActivity;
import com.saifan.wyy_ov.ui.view.BootstrapButton;
import com.saifan.wyy_ov.ui.view.NoScrollGridView;
import com.saifan.wyy_ov.utils.CameraUtil;
import com.saifan.wyy_ov.utils.DialogUtil;
import com.saifan.wyy_ov.utils.FileUtils;
import com.saifan.wyy_ov.utils.LogUtil;
import com.saifan.wyy_ov.utils.PictureUtil;
import com.saifan.wyy_ov.utils.PopUtil;
import com.saifan.wyy_ov.utils.StringUtil;
import com.saifan.wyy_ov.utils.ToastUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @version V1.0.0
 * @author: lomasky
 * @date: 2015-5-14 21:48:21
 * @descrption 租售信息发布
 */

public class RentalinfoReleaseActivity extends BaseActivity implements CompoundButton.OnCheckedChangeListener {

    private PopupWindow popupWindow;
    private List<String> list = new ArrayList<String>();
    private ArrayList<PopBean> propertyTypes, types, ways;
    private RoomInfoBean roomInfoBean;
    private ArrayList<String> selectList;
    private CommentsPicAdapter adapter;
    private final int SELECT_IMG = 0;
    private final int SELECT_PHOTO_TAKEPHOTO = 1;
    private static final int CHOSE_CONTACTS = 1234;
    private String picName = "";
    private int selectPostion = 0;
    private int CZCS_LX = 1;
    private BootstrapButton release;
    private RentalRequestBean requestBean;
    private Toolbar toolbar;
    private RadioButton radioButton1;
    private RadioButton radioButton2;
    private RadioGroup radiogroup;
    private TextView propertyType;
    private EditText shi;
    private EditText ting;
    private EditText wei;
    private EditText area;
    private EditText pricerental;
    private LinearLayout layoutrentalandpreice;
    private EditText pricesale;
    private LinearLayout layoutsalereice;
    private TextView type;
    private TextView way;
    private LinearLayout layoutrentalandtype;
    private EditText address;
    private EditText contacts;
    private EditText tel;
    private EditText title;
    private EditText info;
    private NoScrollGridView picgrid;
    private ScrollView scrollView;
    private TextView jishu;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        roomInfoBean = getRoomInfoBean();
        selectList = new ArrayList<String>();
        setContentView();

    }



    public void setContentView() {
        setContentView(R.layout.activity_rental_release_info);
        this.scrollView = (ScrollView) findViewById(R.id.scrollview);
        this.release = (BootstrapButton) findViewById(R.id.release);
        this.picgrid = (NoScrollGridView) findViewById(R.id.pic_grid);
        this.info = (EditText) findViewById(R.id.info);
        this.title = (EditText) findViewById(R.id.title);
        this.tel = (EditText) findViewById(R.id.tel);
        this.contacts = (EditText) findViewById(R.id.contacts);
        this.address = (EditText) findViewById(R.id.address);
        this.layoutrentalandtype = (LinearLayout) findViewById(R.id.layout_rentalandtype);
        this.way = (TextView) findViewById(R.id.way);
        this.type = (TextView) findViewById(R.id.type);
        this.layoutsalereice = (LinearLayout) findViewById(R.id.layout_salereice);
        this.pricesale = (EditText) findViewById(R.id.price_sale);
        this.layoutrentalandpreice = (LinearLayout) findViewById(R.id.layout_rentalandpreice);
        this.pricerental = (EditText) findViewById(R.id.price_rental);
        this.area = (EditText) findViewById(R.id.area);
        this.wei = (EditText) findViewById(R.id.wei);
        this.ting = (EditText) findViewById(R.id.ting);
        this.shi = (EditText) findViewById(R.id.shi);
        this.propertyType = (TextView) findViewById(R.id.propertyType);
        this.radiogroup = (RadioGroup) findViewById(R.id.radiogroup);
        this.radioButton2 = (RadioButton) findViewById(R.id.radioButton2);
        this.radioButton1 = (RadioButton) findViewById(R.id.radioButton1);
        this.toolbar = (Toolbar) findViewById(R.id.toolbar);
        jishu= (TextView) findViewById(R.id.jishu);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        radioButton1.setOnCheckedChangeListener(this);
        radioButton2.setOnCheckedChangeListener(this);


        contacts.setText(StringUtil.returnShow(roomInfoBean.getWYKHDA_LC()));
        tel.setText(StringUtil.returnShow(roomInfoBean.getWYKHDA_SJ()));
        adapter = new CommentsPicAdapter(selectList, RentalinfoReleaseActivity.this);
        picgrid.setAdapter(adapter);
        picgrid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (selectList.size() < 5) {
                    selectPostion = position - 1;
                    showSelectImgDialog(position == 0 ? false : true, position - 1);
                } else {
                    selectPostion = position;
                    showSelectImgDialog(true, position);
                }
            }
        });

        info.addTextChangedListener(new TextWatcher() {


            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                jishu.setText(s.length() + "/100" );
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

    }


    public void getContacts(View view) {

        if (Build.VERSION.SDK_INT >= 23) {
            int checkCallPhonePermission = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS);
            if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_CONTACTS }, CHOSE_CONTACTS);
                return;
            }else {
                Intent i = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
                startActivityForResult(i, CHOSE_CONTACTS);
            }
        }else {
            Intent i = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
            startActivityForResult(i, CHOSE_CONTACTS);
        }


    }


    public void submit(View view) {
        if (isEmpty(propertyType)) {
            scrollView.scrollTo(0, 0);
            showPropertyType(propertyType);
            return;
        }

        if (isEmpty(area)) {
            ToastUtil.showToast(this, "面积不能为空");
            return;
        }
        if (CZCS_LX == 1) {

            if (isEmpty(pricerental)) {
                ToastUtil.showToast(this, "租金不能为空");
                return;
            }
        } else if (CZCS_LX == 2) {
            if (isEmpty(pricesale)) {
                ToastUtil.showToast(this, "价格不能为空");
                return;
            }
        }


        if (isEmpty(address)) {
            ToastUtil.showToast(this, "地址不能为空");

            return;
        }
        if (isEmpty(contacts)) {
            ToastUtil.showToast(this, "联系人不能为空");

            return;
        }
        if (isEmpty(tel)) {
            ToastUtil.showToast(this, "联系人电话不能为空");

            return;
        }
        if (isEmpty(title)) {
            ToastUtil.showToast(this, "标题不能为空");

            return;
        }

        GetData getData = new GetData();
        RequestParams params = new RequestParams();

        params.addBodyParameter(Api.RentalInfo.RENTAL_INFO, initParams());
        for (int i = 0; i < selectList.size(); i++) {
            File file = new File(PictureUtil.getCompressBitmap(selectList.get(i)));
            if (file.exists()) {
                LogUtil.i(FileUtils.getFileSize(FileUtils.getFileSize(file.getPath())));
                params.addBodyParameter(file.getName(), file);
            }

        }

        getData.getData(Api.RentalInfo.RENTAL_INFO_SUBMIT, params, new RequestCallBack<String>() {
            @Override
            public void onStart() {
                super.onStart();
                DialogUtil.showProgressDialog(RentalinfoReleaseActivity.this, "正在提交");
            }

            @Override
            public void onCancelled() {
                super.onCancelled();
                LogUtil.i("取消请求");
            }

            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {

                if (!StringUtil.isNullOrEmpty(responseInfo.result)) {
                    try {
                        JSONObject jsonObject = new JSONObject(responseInfo.result.toString());
                        String code = jsonObject.getString("Code");
                        if (code.equals("200")) {
                            ToastUtil.showToast(RentalinfoReleaseActivity.this, "提交成功");
                            DialogUtil.closeProgressDialog();
                            finish();

                        } else if (code.equals("202")) {
                            DialogUtil.closeProgressDialog();
                            ToastUtil.showToast(RentalinfoReleaseActivity.this, "保存失败，信息未做修改 !");
                        } else {
                            LogUtil.e(code);
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                } else {
                    LogUtil.e("ServerError");
                }
            }

            @Override
            public void onFailure(HttpException e, String s) {
                LogUtil.i(s);
                ToastUtil.showToast(RentalinfoReleaseActivity.this, getString(R.string.network_error));
                DialogUtil.closeProgressDialog();
            }

        });

    }


    private String initParams() {
        requestBean = new RentalRequestBean();
        requestBean.setCZCS_XXQK(info.getText().toString().trim());
        requestBean.setCZCS_DZ(address.getText().toString().trim());
        requestBean.setCZCS_LXR(contacts.getText().toString().trim());
        requestBean.setCZCS_LXDH(tel.getText().toString().trim());
        requestBean.setCZCS_WYLXMC(propertyType.getText().toString());
        requestBean.setCZCS_BT(title.getText().toString().trim());
        requestBean.setCZCS_CZLX(CZCS_LX==1?type.getText().toString():"");
        requestBean.setXMBS(roomInfoBean.getXMBS());

        requestBean.setCZCS_LX(CZCS_LX);
        requestBean.setCZCS_KHWJ(roomInfoBean.getWYKHDA_ZJ());
        requestBean.setCZCS_JZMJ(Float.valueOf(area.getText().toString().trim()));
        StringBuffer sb = new StringBuffer();
        if (!isEmpty(shi)) {
            sb.append(shi.getText().toString() + "室");
        } else {
            sb.append("0室");
        }
        if (!isEmpty(ting)) {
            sb.append(ting.getText().toString() + "厅");
        } else {
            sb.append("0厅");
        }
        if (!isEmpty(wei)) {
            sb.append(wei.getText().toString() + "卫");
        } else {
            sb.append("0卫");
        }

        if (CZCS_LX == 1) {
            requestBean.setCZCS_JE(pricerental.getText().toString());
            requestBean.setCZCS_CZLX(type.getText().toString() + "/" + way.getText().toString());
        } else if (CZCS_LX == 2) {
            requestBean.setCZCS_JE(pricesale.getText().toString());

        }
        requestBean.setCZCS_HXMC(sb.toString());


        return new Gson().toJson(requestBean);
    }

    /**
     * 弹出出租类型（分租或合租）
     */
    public void showType(final View view) {

        final int id = view.getId();
        types = new ArrayList<>();
        types.add(new PopBean("整租"));
        types.add(new PopBean("合租"));


        PopupWindow popupWindow = PopUtil.createPopupWindow(this, types, new IListViewOnClick() {
            @Override
            public void onClick(int position) {
                ((TextView) findViewById(id)).setText(types.get(position).getName());

            }
        });

        popupWindow.setWidth(view.getMeasuredWidth());
        popupWindow.showAsDropDown(view);


    }

    /**
     * 弹出物业类型
     */
    public void showPropertyType(View view) {

        final int id = view.getId();
        propertyTypes = new ArrayList<>();
        propertyTypes.add(new PopBean("住宅"));
        propertyTypes.add(new PopBean("商铺"));
        propertyTypes.add(new PopBean("写字楼"));
        propertyTypes.add(new PopBean("其它"));
        PopupWindow popupWindow = PopUtil.createPopupWindow(this, propertyTypes, new IListViewOnClick() {
            @Override
            public void onClick(int position) {
                ((TextView) findViewById(id)).setText(propertyTypes.get(position).getName());

            }
        });
        popupWindow.setWidth(view.getMeasuredWidth());
        popupWindow.showAsDropDown(view);
    }

    /**
     * 弹出租金方式
     */
    public void showWay(View view) {

        final int id = view.getId();
        ways = new ArrayList<>();
        ways.add(new PopBean("押一付一"));
        ways.add(new PopBean("押一付三"));
        ways.add(new PopBean("押一付六"));
        PopupWindow popupWindow = PopUtil.createPopupWindow(this, ways, new IListViewOnClick() {
            @Override
            public void onClick(int position) {
                ((TextView) findViewById(id)).setText(ways.get(position).getName());

            }
        });

        popupWindow.setWidth(view.getMeasuredWidth());
        popupWindow.showAsDropDown(view);
    }


    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (isChecked) {
            buttonView.setTextColor(Color.RED);
            if (buttonView.getId() == R.id.radioButton1) {
                CZCS_LX = 1;
                layoutsalereice.setVisibility(View.GONE);
                layoutrentalandpreice.setVisibility(View.VISIBLE);
                layoutrentalandtype.setVisibility(View.VISIBLE);
            } else {
                CZCS_LX = 2;
                layoutsalereice.setVisibility(View.VISIBLE);
                layoutrentalandpreice.setVisibility(View.GONE);
                layoutrentalandtype.setVisibility(View.GONE);
            }
        } else {
            buttonView.setTextColor(Color.BLACK);
        }

    }

    public void selectImg() {
        storePermission(SELECT_IMG);

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (requestCode == SELECT_IMG) {
            if (resultCode == RESULT_OK) {
                this.selectList = data.getStringArrayListExtra("data");
                adapter.list = selectList;
                adapter.notifyDataSetChanged();
            }
        } else if (requestCode == SELECT_PHOTO_TAKEPHOTO) {
            if (resultCode == RESULT_OK) {
                Bitmap bitmap = data.getParcelableExtra("data") ;
                File file = FileUtils. bitmapToFile(bitmap);
                FileUtils.toAlbum(this,file);
                picName=file.getAbsolutePath();
                if (selectPostion == -1) {
                    this.selectList.add(picName);
                } else {
                    this.selectList.set(selectPostion, picName);
                }
                adapter.list = selectList;
                adapter.notifyDataSetChanged();
            }
        } else if (requestCode == CHOSE_CONTACTS) {
            if (!(resultCode == RESULT_OK)) {
                return;
            }
            if (data == null) {
                return;
            }
            Uri uri = data.getData();
            String name = "";
            String number = "";


                try {
                    Cursor cursor = getContentResolver().query(uri, null, null, null,
                            null);
                    if (cursor != null&&cursor.moveToFirst()) {

                        int contactId = Integer.valueOf(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)));
                        name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                        if (Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
                            Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId, null, null);
                            if (phones.moveToFirst()) {
                                //遍历所有的电话号码
                                number = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

                            }
                        }
                        cursor.close();
                        tel.setText(number.replace(" ",""));
                        contacts.setText(name);
                    }
                } catch (Exception e) {
                    LogUtil.e(e.toString());
                }





        }
    }


    //显示选择图片的对话框
    private void showSelectImgDialog(boolean hasDelete, final int deletePostion) {
        String[] items;
        if (hasDelete)
            items = new String[]{"从相册中选择", "拍照", "删除"};
        else
            items = new String[]{"从相册中选择", "拍照"};


        AlertDialog dialog = new AlertDialog.Builder(  this)
                .setTitle("选择图片")

                .setItems(items, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (which == 0) {
                            selectImg();
                        } else if (which == 2) {
                            selectList.remove(deletePostion);
                            adapter.list = selectList;
                            adapter.notifyDataSetChanged();
                        } else {
                            cammerPermission(SELECT_PHOTO_TAKEPHOTO);
                        }
                        dialog.dismiss();
                    }
                })
                .show();
    }

    public void cammerPermission(int position) {
        if (Build.VERSION.SDK_INT >= 23) {
            int checkCallPhonePermission = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
            if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, position);
                return;
            } else {

                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(intent, SELECT_PHOTO_TAKEPHOTO);


            }
        } else {

            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(intent, SELECT_PHOTO_TAKEPHOTO);


        }

    }

    public void storePermission(int position) {
        if (Build.VERSION.SDK_INT >= 23) {
            int checkCallPhonePermission = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
            if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, position);
                return;
            } else {

                Intent intent = new Intent(this, PhotoAlbumActivity.class);
                intent.putStringArrayListExtra("data", selectList);
                startActivityForResult(intent, SELECT_IMG);
            }
        } else {
            Intent intent = new Intent(this, PhotoAlbumActivity.class);
            intent.putStringArrayListExtra("data", selectList);
            startActivityForResult(intent, SELECT_IMG);
        }

    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        if (requestCode == SELECT_PHOTO_TAKEPHOTO) {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                // Permission Granted
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(intent, SELECT_PHOTO_TAKEPHOTO);


            } else {
                // Permission Denied
                Toast.makeText(this, "您禁用摄像头", Toast.LENGTH_SHORT)
                        .show();

            }
        }  else if (requestCode == CHOSE_CONTACTS) {

            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                // Permission Granted
                Intent i = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
                startActivityForResult(i, CHOSE_CONTACTS);


            } else {
                // Permission Denied
                Toast.makeText(this, "您禁用了读取通讯录权限", Toast.LENGTH_SHORT)
                        .show();

            }
        }


        else {

            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                // Permission Granted
                Intent intent = new Intent(this, PhotoAlbumActivity.class);
                intent.putStringArrayListExtra("data", selectList);
                this.startActivityForResult(intent, SELECT_IMG);


            } else {
                // Permission Denied
                Toast.makeText(this, "您禁用本地存储读写", Toast.LENGTH_SHORT)
                        .show();

            }
        }

    }

    /**
     * @version V1.0.0
     * @author: lomasky
     * @date: 2015-05-05 14:41
     * @descrption 物业服务
     */
    public static class PropertyFragment extends Fragment implements View.OnClickListener {


        View view;


        private Context context;
        private ImageView propertybill;
        private ImageView parkingcard;
        private ImageView rateofprogress;
        private ImageView survey;
        private ImageView decorationapply;
        private ImageView reportabouttherepair;
        private ImageView complaintandadvice;
        private ImageView visitormanage;
        private ImageView photograph;
        private String picName;


        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            context = getActivity();
            // Inflate the layout for this fragment
            View view = inflater.inflate(R.layout.fragment_property, container, false);
            this.photograph = (ImageView) view.findViewById(R.id.photograph);
            this.visitormanage = (ImageView) view.findViewById(R.id.visitor_manage);
            this.complaintandadvice = (ImageView) view.findViewById(R.id.complaint_and_advice);
            this.reportabouttherepair = (ImageView) view.findViewById(R.id.report_about_the_repair);
            this.decorationapply = (ImageView) view.findViewById(R.id.decoration_apply);
            this.survey = (ImageView) view.findViewById(R.id.engagedService);
            this.rateofprogress = (ImageView) view.findViewById(R.id.rate_of_progress);
            this.parkingcard = (ImageView) view.findViewById(R.id.parking_card);
            this.propertybill = (ImageView) view.findViewById(R.id.property_bill);


            // onclick
            this.propertybill.setOnClickListener(this);
            this.parkingcard.setOnClickListener(this);
            this.rateofprogress.setOnClickListener(this);
            this.survey.setOnClickListener(this);
            this.decorationapply.setOnClickListener(this);
            this.reportabouttherepair.setOnClickListener(this);
            this.complaintandadvice.setOnClickListener(this);
            this.visitormanage.setOnClickListener(this);
            this.photograph.setOnClickListener(this);

            return view;
        }


        /**
         * 物业账单
         */
        public void onProperty_bill() {
            if (((MainActivity)getActivity()).getRoomInfoBean().getUserType() == 3){
                ToastUtil.showToast(getActivity(), "您的权限不能进行此操作");
                return;
            }
            Intent intent = new Intent(context, FeeQueryActivity.class);
            startActivity(intent);

        }

        /**
         * 停车卡续费
         */
        public void onParking_card() {
            if (((MainActivity)getActivity()).getRoomInfoBean().getUserType() == 3){
                ToastUtil.showToast(getActivity(), "您的权限不能进行此操作");
                return;
            }
            ToastUtil.showToast(context, "停车卡续费暂未开通，敬请期待！");

        }

        /**
         * 进度查询
         */
        public void onRate_of_progress() {
            if (((MainActivity)getActivity()).getRoomInfoBean().getUserType() == 3){
                ToastUtil.showToast(getActivity(), "您的权限不能进行此操作");
                return;
            }
            Intent intent = new Intent(context, ProgressQueryActivity.class);
            startActivity(intent);

        }



        /**
         * 社区调查
         */
        public void onSurvey() {
            if (((MainActivity)getActivity()).getRoomInfoBean().getUserType() == 3){
                ToastUtil.showToast(getActivity(), "您的权限不能进行此操作");
                return;
            }
            Intent intent =new Intent();
            intent.setClass(context,QuestionnaireInfoActivity.class);
            startActivity(intent);
        }

        /**
         * 装修申请
         */
        public void onDecoration_apply() {
            if (((MainActivity)getActivity()).getRoomInfoBean().getUserType() == 3){
                ToastUtil.showToast(getActivity(), "您的权限不能进行此操作");
                return;
            }
            Intent intent = new Intent(context, DecorationApplyActivity.class);
            startActivity(intent);

        }

        /**
         * 报事报修
         */
        public void onReport_about_the_repair() {
            if (((MainActivity)getActivity()).getRoomInfoBean().getUserType() == 3){
                ToastUtil.showToast(getActivity(), "您的权限不能进行此操作");
                return;
            }
            Intent intent = new Intent(context, RepairActivity.class);
            startActivity(intent);

        }

        /**
         * 投诉建议
         */
        public void onComplaint_and_advice() {
            if (((MainActivity)getActivity()).getRoomInfoBean().getUserType() == 3){
                ToastUtil.showToast(getActivity(), "您的权限不能进行此操作");
                return;
            }
            Intent intent = new Intent(context, ComplaintandadviceActivity.class);
            startActivity(intent);


        }

        /**
         * 访客管理
         */
        public void onVisitor_manage() {
            if (((MainActivity)getActivity()).getRoomInfoBean().getUserType() == 3){
                ToastUtil.showToast(getActivity(), "您的权限不能进行此操作");
                return;
            }
            Intent intent = new Intent(context, VisitorManageActivity.class);
            startActivity(intent);

        }

        /**
         * 随手拍
         */
        public void onPhotograph() {
            if (((MainActivity)getActivity()).getRoomInfoBean().getUserType() == 3){
                ToastUtil.showToast(getActivity(), "您的权限不能进行此操作");
                return;
            }
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

            startActivityForResult(intent, 1111);

        }

        @Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            LogUtil.i(resultCode+"onActivityResult");
            if (resultCode != -1) {
                return;
            }


            Intent intent = new Intent(getActivity(), PhotographActivity.class);
            intent.putExtra("picName",picName);
            startActivity(intent);
        }

        @Override
        public void onClick(View v) {
            int id = v.getId();
            if (id == R.id.property_bill) {
                onProperty_bill();

            } else if (id == R.id.parking_card) {
                onParking_card();

            } else if (id == R.id.rate_of_progress) {
                onRate_of_progress();

            } else if (id == R.id.engagedService) {
                onSurvey();

            } else if (id == R.id.decoration_apply) {
                onDecoration_apply();

            } else if (id == R.id.report_about_the_repair) {
                onReport_about_the_repair();

            } else if (id == R.id.complaint_and_advice) {
                onComplaint_and_advice();

            } else if (id == R.id.visitor_manage) {
                onVisitor_manage();

            } else if (id == R.id.photograph) {
                onPhotograph();

            } else {
            }

        }
    }


}
